home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!usenet
- From: jgealow@mtl.mit.edu (Jeffrey C. Gealow)
- Newsgroups: comp.std.c++
- Subject: Re: initialization of nonlocal static objects
- Date: 26 Mar 1996 00:30:05 GMT
- Organization: MIT Microsystems Technology Laboratories
- Sender: jgealow@gator.mit.edu
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <ky3f6w679u.fsf@gator.mit.edu>
- References: <4j1tm6$bmu@senator-bedfellow.MIT.EDU>
- <9603251201.AA24987@lts.sel.alcatel.de>
- NNTP-Posting-Host: taumet.eng.sun.com
- X-Nntp-Posting-Host: gator.mit.edu
- In-Reply-To: James Kanze US/ESC 60/3/141 #40763's message of 25 Mar 1996
- 16:16:43 GMT
- X-Newsreader: Gnus v5.1
- Content-Length: 1587
- X-Lines: 61
-
- In article <9603251201.AA24987@lts.sel.alcatel.de> James Kanze
- US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de> writes:
-
- In article <4j1tm6$bmu@senator-bedfellow.MIT.EDU> jgealow@mtl.mit.edu
- (Jeffrey C. Gealow) writes:
-
- |> The technique described in the ARM 3.4 annotation cannot be applied to
- |> const objects since the values of the objects may not be changed.
-
- No. Const has nothing to do with the question, since objects only
- become const after construction.
-
- I don't understand James Kanze's comment. Consider:
-
- // file nifty_library.h:
- //
-
- class X {
- public:
- int i;
- X() : i(10) {};
- };
-
- extern const X obj;
-
- class nifty_counter {
- static nifty_count;
- public:
- nifty_counter() {
- if (nifty_count++ == 0) {
- obj.i = 5;
- }
- }
- };
-
-
- // file nifty_library.cc:
- //
-
- #include "nifty_library.h"
-
- const X obj;
-
- The intent of the statement obj.i = 5 in nifty_counter::nifty_counter()
- is to "initialize" obj. But formally, obj is initialized by the
- default constructor for class X.
-
- % CC -c nifty_library.cc
- "nifty_library.h", line 17: Error: The left operand cannot be assigned to.
- 1 Error(s) detected.
- % CC -Dconst="" -c nifty_library.cc
-
- Perhaps the problem may be circumvented by casting away const: ((X) obj).i = 5;
-
- I believe that the intent of the current draft is that rule in ARM 3.4
- hold only for uses invoked directly or indirectly from main, but not
- for uses which result from the construction of other static objects.
-
- Perhaps the intent should be clarified in the text of the draft.
-
- Jeff
-
-
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-